﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PlainOldVersionControl.IViews.Base;
using PlainOldVersionControl.BusinessLogic.Base;
using PlainOldVersionControl.Domain;
using PlainOldVersionControl.ErrorHandling;

namespace PlainOldVersionControl.UI
{
    public partial class CreateCommit : Form, ICommit
    {
        public CreateCommit()
        {
            InitializeComponent();
        }

        private void CreateCommit_Load(object sender, EventArgs e)
        {

        }

        #region ICommit Members

        public string Hash
        {
            set { lblStatus.Text = string.Format("Status : Hash = {0}", value); }
        }

        public string Author
        {
            get
            {
                return UserSettings.Default.UserName;
            }
            set
            {
                ;
            }
        }

        public string Message
        {
            get
            {
                return txtMessage.Text;
            }
            set
            {
                ;
            }
        }

        public DateTime CreatedDate
        {
            set { ; }
        }

        public string TreeHash
        {
            set { ; }
        }

        public string ParentCommit
        {
            set { ; }
        }

        #endregion

        private void btnAction_Click(object sender, EventArgs e)
        {
            try
            {
                btnAction.Enabled = false;
                Cursor = Cursors.WaitCursor;
                TreeBL.CreateCommit(this as ICommit);
                MessageBox.Show("Commit Completed");
            }
            catch (ValidationException ex)
            {
                MessageBox.Show(ex.Message);
                btnAction.Enabled = true;
            }
            catch (Exception ex)
            {
                ErrorHandlingHelper.HandleError(ex);
            }
            finally
            {
                Cursor = Cursors.Default;
            }
        }
    }
}
